namespace AltNetUK.Models
{
    using System;
    using System.Collections.ObjectModel;
    using System.Xml;
    using System.Xml.Schema;
    using System.Xml.Serialization;
    using SimpleWebServices;

    [XmlRoot(ElementName = "schedule")]
    public sealed class ScheduleCollection : Collection<Event>, IXmlSerializable
    {
        public XmlSchema GetSchema()
        {
            throw new NotSupportedException();
        }

        public void ReadXml(XmlReader reader)
        {
            if (null == reader)
            {
                throw new ArgumentNullException("reader");
            }

            XmlDocument document = new XmlDocument();
            document.LoadXml(reader.ReadOuterXml());
            foreach (XmlNode node in document.SelectNodes("/schedule/event"))
            {
                this.Add(node.OuterXml.Deserialize<Event>());
            }
        }

        public void WriteXml(XmlWriter writer)
        {
        }
    }
}